package cc.idoone.spring_boot_hello.actuator;

import org.springframework.boot.actuate.health.Health;
import org.springframework.boot.actuate.health.HealthIndicator;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Component;

/**
 * 自定义健康状态检测类
 *
 * @author hemj
 * @since 2017/10/18
 */
@Component
public class CusStatusHealthIndicator implements HealthIndicator {

	@Override
	public Health health() {
		int errorCode = check();
		// if (errorCode != 0) {
		// 	return Health.down()
		// 			.withDetail("status", errorCode)
		// 			.withDetail("message", "服务故障")
		// 			.build();
		// }
		return Health.up()
				.withDetail("status", errorCode)
				.withDetail("message", "服务正常").build();
	}

	private int check() {
		// 对监控对象的检测操作
		return HttpStatus.NOT_FOUND.value();
	}
}
